package sg.edu.nus.comp.qa;

import java.util.List;
import java.util.Scanner;

import sg.edu.nus.comp.qa.question.ComparableQuestion;

public class QACommandLine {
	private Scanner scanner;
	private QASorter sorter = new QASorter();
	public QACommandLine() {
		scanner = new Scanner(System.in);
	}

	public void command() {
		long start, end;
		System.out.print(">");
		String input = scanner.nextLine();
		while (!input.equalsIgnoreCase("q") && !input.equalsIgnoreCase("quit")
				&& !input.equalsIgnoreCase("exit")) {
			start = System.currentTimeMillis();
			List<ComparableQuestion> questionList = sorter.sort(input);
			end = System.currentTimeMillis();
			System.out.println("----Time takes: " + (end - start) + "ms----");
			printQuestion(questionList, 10);
			System.out.print(">");
			input = scanner.nextLine();
		}
	}

	private void printQuestion(List<ComparableQuestion> questionList, int m) {
		for (int i = 0; i < m && i<questionList.size(); i++) {
			ComparableQuestion question = questionList.get(i);
			System.out.println("->" + question.getQuestion());
			System.out.println("  " + question.getAnswer());
			System.out.printf("  Mark: %.2f\n", question.getValue());
			System.out.println("----");
		}
	}
}
